package com.example.j280_webproject.servlet;

import com.example.j280_webproject.day036.JDBC01_register;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();

        JDBC01_register jdbc01_register = new JDBC01_register();
        try {
            boolean action = jdbc01_register.register(username,password);
            if (action){
                System.out.println("恭喜您！注册成功！");
                writer.println("恭喜您！注册成功！");
            }
            else {
                System.out.println("很遗憾！注册失败！");
                writer.println("很遗憾！注册失败！");
            }
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
//            System.out.println("系统繁忙请稍后再试！！！");
        }
    }
}
